import {
	Component,
	OnInit,
	OnDestroy,
	AfterViewInit,
	EventEmitter,
	Input,
	Output
} from '@angular/core';
@Component({
	selector: 'TinyMCE',
	templateUrl: 'TinyMCE.component.html'
})

export class TinyMCEComponent implements OnInit {
	@Input() elementId: String;
	@Output() onEditorKeyup = new EventEmitter<any>();
	editor;
	ngOnInit() { }
	ngAfterViewInit() {
		//应该封到指令中
		// tinyMCE配置文档https://www.tinymce.com/docs/configure/
		tinymce.init({
			selector: '#' + this.elementId,
			plugins: ['link', 'paste', 'table'],
			skin_url: '../assets/skins/lightgray',
			setup: editor => {
				this.editor = editor;
				editor.on('keyup', () => {
					const content = editor.getContent();
					this.onEditorKeyup.emit(content);
				});
			},
		});
	}

	ngOnDestroy() {
		tinymce.remove(this.editor);
	}


}